/**
 * 
 */
package org.bankabeule.ui.actions;

import org.bankabeule.Model;
import org.bankabeule.core.ModelListener;
import org.bankabeule.core.ModelManager;
import org.eclipse.jface.action.Action;

/**
 * @author sdudoit
 *
 */
public abstract class AbstractAction extends Action implements ModelListener {

	
	public AbstractAction() {
		setEnabled(false);
		// register as listener
		ModelManager.get().addModelListener(this);
	}

	
	@Override
	protected void finalize() throws Throwable {
		ModelManager.get().removeModelListener(this);
		super.finalize();
	}
	
	
	/* (non-Javadoc)
	 * @see org.bankabeule.core.ModelListener#modelDirty(org.bankabeule.Model)
	 */
	public void modelDirty(Model model) {
		// TODO Auto-generated method stub

	}

	/* (non-Javadoc)
	 * @see org.bankabeule.core.ModelListener#modelLoaded(org.bankabeule.Model)
	 */
	public void modelLoaded(Model model) {
		setEnabled(true);
	}

	/* (non-Javadoc)
	 * @see org.bankabeule.core.ModelListener#modelSaved(org.bankabeule.Model)
	 */
	public void modelSaved(Model model) {
	}

	/* (non-Javadoc)
	 * @see org.bankabeule.core.ModelListener#modelUnloaded(org.bankabeule.Model)
	 */
	public void modelUnloaded(Model model) {
		setEnabled(false);
	}

}
